package operations;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class FindOperation implements IOperation{
    public void work(BookList bookList) {
        System.out.println("查找图书！");

        System.out.println("请输入你要查找图书的名字:>");
        Scanner scanner = new Scanner(System.in);
        String findName = scanner.nextLine();

        int currentUserSide = bookList.getUsedSize();
        for (int i = 0; i < currentUserSide; i++) {
            //BookList中books被封装后，不能直接去访问books[i]，只能在BookList中设置一个方法返回books[i]，再遍历
            Book findBook = bookList.getPosBook(i);

            //找到书
            if(findName.equals(findBook.getName())){
                System.out.println("找到这本书了！");
                System.out.println(findBook);
                return;
            }
        }
        //遍历完没找到
        System.out.println("没有你要查找的图书！");
    }
}




